import book.BookList;
import exception.UserNameException;
import exception.UserchooseException;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {
    public static User login() throws UserNameException, UserchooseException {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入你的姓名:");
        String name = input.nextLine();
        if (!name.equals("bit")) {
            throw new UserNameException("用户名错误!");
        }
        System.out.println("请输入你的身份 1----->管理员   0 ------> 普通用户:");
        int n = input.nextInt();
        if (n == 1 || n == 0) {

            return n == 1 ? new AdminUser(name) : new NormalUser(name);
        } else {
            throw new UserchooseException();
        }

    }
    public static void main(String[] args) throws UserchooseException {
        BookList bookList = new BookList();

        try {
            User user = Main.login();
            while (true) {
                int choose = user.menu();
                user.work(choose,bookList);
            }
        }catch (UserchooseException e) {
            e.printStackTrace();
            System.out.println("捕捉到了 UserchooseException 异常");
        } catch (UserNameException e){
            e.printStackTrace();
            System.out.println("捕捉到了 UserNameException 异常");
        }finally {
            System.out.println("finally......");
        }



    }
}
